package com.lmscn.lms.api.model;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

import java.util.List;

/**
 * Created by Czl on 2015/7/25.
 */
@SuppressWarnings("serial")
public class LessonStudent extends Model<LessonStudent> {

    public static final LessonStudent dao = new LessonStudent();

    /**
     * 保存课件学员关系表
     * @param ls
     * @param courseStudentId
     * @param courseId
     * @param studentId
     * @param lessonId
     */
    public void saveLessonStudent(LessonStudent ls,Long courseStudentId,Long courseId,Long studentId,Long lessonId){
        ls.set("course_student_id",courseStudentId);
        ls.set("course_id",courseId);
        ls.set("student_id",studentId);
        ls.set("lesson_id",lessonId);
        ls.remove("id").save();
    }

    /**
     * 删除课件学员信息
     * @param courseStudentId
     * @param courseId
     * @param studentId
     * @param lessonId
     */
    public void deleteLessonStudent(Long courseStudentId,Long courseId,Long studentId,Long lessonId){
        Db.update("delete from t_lesson_student " +
                "where course_student_id =? and course_id=? and student_id=? and lesson_id=?",courseStudentId,courseId,studentId,lessonId);
    }

    public LessonStudent findByCourseIdAndStudentId(Long courseId, Long studentId){
        return dao.findFirst("select * from t_lesson_student where course_id = ? and student_id = ?", courseId, studentId);
    }
}
